$(document).ready(function () {

    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 30,
        loop: true,
        autoplay: 4000
    });



    /***圈中热贴****/

    function groupHotPost() {
        myAjaxFunc({
            url: community + "getPagePost",
            type: 'post',
            dataType: 'json',
            data: {groupId: '1000',listCurrentPage:'1'},
            mySuccess: function (data) {

                let content = data.data.pageDate.list
                    , hotPost = '';


                for (let i = 0, ig = 4; i < ig; i++) {


                    // 现在老版本读取图片，imgUrls的第一张
                    // 新版本后应该读取封面图片，就无需用到此处
                    let imgUrl=content[i].imgUrls;
                    let imgList=[];

                    if (notNull(imgUrl)) {
                        imgList = imgUrl.split(',');
                    }
                    //

                    var postItemTexth4=html_encode(content[i].textContentShort);

                    hotPost+=

                        '        <div class="textItem">' +
                        '            <div class="innerText">' +
                        '                <a href="groupPostDetail.html?postId='+content[i].id+'" class="PostTile">'+content[i].title+'</a>' +
                        '                <p>'+postItemTexth4+'</p>' +
                        '            </div>' +
                        '            <div class="coverImgBox">' +
                        '                <img class="coverImg" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1756667326,3522539385&fm=27&gp=0.jpg">' +
                        '            </div>' +
                        '        </div>'


                }
                var txtP='<p class="txtP">圈中热帖</p>';

                $('#groupHotPost').empty().append(txtP+hotPost);



            }
        });

    }

    groupHotPost()


    getGroupData(1);

    /****************************综合社区社区帖子********************************/

    let indexGroupPostList= $("#postInnerText");

    function getGroupData(listCurrentPage){

        myAjaxFunc({
            url: community + "getPagePost",
            type: 'post',
            dataType: 'json',
            data: {groupId: 1000, listCurrentPage: listCurrentPage},
            mySuccess: function (data) {
                if (isResponseSuccess('success', data)) {
                    let postData = isResponseSuccess('getdata', data);
                    postData.list.roles = set_roles();   //配置管理员信息
                    postData.list.listCurrentPage = postData.extra.listCurrentPage;  //配置当前页
                    postData.list.geturl = geturlimg;     //配置图片加载地址
                    let leng = postData.list.length;

                    for (let i = 0; i < leng; i++) {
                        let imgList = '';
                        let imgUrl = postData.list[i].imgUrls;
                        if (notNull(imgUrl)) {
                            imgList = postData.list[i].imgUrls.split(',');
                        }
                        postData.list[i].imgUrls = imgList;
                        postData.list[i].textContentShort = html_encode(postData.list[i].textContentShort);

                        console.log(postData.list[i].imgUrls)

                    }


                    //配置图片为数组

                    let pageInfo = postData.extra,
                        allpage = pageInfo.listPageCount, //总页数
                        atpage = pageInfo.listCurrentPage; //当前页数

                    creationPage(allpage,atpage)


                    console.log(postData);

                    var html = template('community-post-list-template', postData);

                    indexGroupPostList.empty().append(html);

                    setTimeout(showPri(), 200);//返回显示点赞数据

                    changeImg();//更改图片样式
                }
            }
        });
    }



    function creationPage(allpage,atpage) {

        Page({
            num:allpage,			//页码数
            startnum:atpage,		//指定页码
            elem:$('#page'),		//指定的元素
            callback:function(n){	//回调函数
                getGroupData(n)
            }
        });
    }



    /****************************首页侧边栏最新贷款*********************************/

    sidebarfn('sidebarProduct','.NewLoansProductList');


    var groupCommentTop='1826';


    /*右边侧栏滚动显示*/
    $(document).scroll(function () {
        let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
            , che = document.documentElement.scrollHeight - (document.documentElement.clientHeight + scrollTop);

        if(scrollTop>420){
            $('.fix_ul').show()
        }else {
            $('.fix_ul').hide()

        }



        console.log(scrollTop);

        var rightboxtx=getDistance( $('.leftGroupPost')).right;
        var bottomboxtx=getDistance( $('.leftGroupPost')).bottom;

        // console.log('topboxtx'+groupCommentTop);
        // console.log('bottomboxtx'+bottomboxtx);


        if(scrollTop>groupCommentTop){
            $('.activityUser').addClass('fixRight');
            $('.activityUser').css({'right':rightboxtx-340+'px'})
        }else {
            $('.activityUser').removeClass('fixRight');

        }
        // console.log(scrollTop);

        if(bottomboxtx<-10){
            $('.activityUser').css({'right':rightboxtx-340+'px'})
            $('.activityUser').show();

        }else {
            $('.activityUser').hide();

        }


    });
    /*END*/



    function changeImg() {
        // var _imga = $('.postImg img');
        // _imga.load(function () {
        //     var Imgheight = $(this).height();
        //     var ImgWidth = $(this).width();
        //     if (Imgheight > ImgWidth) {
        //         $(this).parent().addClass('list_c').removeClass('list_a');
        //     }
        // });

        var _imgb = $('.postImg img');
        _imgb.load(function () {
            var Imgheight = $(this).height();
            var ImgWidth = $(this).width();
            if (Imgheight > ImgWidth) {
                $(this).addClass('forWidth')
            } else {
                $(this).addClass('forHeight')
            }

        })


    }

    changeImg()


});

